package homework3;

import java.util.Scanner;

/*
编写代码模拟三次密码输入的场景。最多能输入三次密码，密码正确，提示“登录成功”,
密码错误，可以重新输 入，最多输入三次。三次均错，则提示退出程序
 */
public class P7 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("设置密码：");
        String s1 = sc.next();
        boolean flag = false;
        for (int i = 0; i < 3; i++) {
            System.out.print("password：");
            String s2 = sc.next();
            if (s1.equals(s2)) {
                flag = true;
                System.out.println("登陆成功！");
                break;
            } else {
                System.out.println("密码错误，请重输!");
            }
        }
        if (flag==false)
            System.out.println("已连续输错3次,退出程序！");
        sc.close();
    }
}
